'''
Created on 2012-3-27

@author: Wang_ZJ
'''
from global_vars import g_dbsession
from common.model.user import user_info
from common import result_object
class user_mgr():
    @classmethod
    def login(self, username, passwd):
        ''' return a result_object instance
        '''
        retobj = result_object()
        query = g_dbsession.query(user_info)
        user = query.select_by(user_name=username)
        if not user:
            retobj.result = False; retobj.errstr = u'找不到该用户'
            return retobj
        if user.c.password != passwd:
            retobj.result = False; retobj.errstr = u'用户密码错误'
            return retobj
        from datetime import datetime
        user.c.login_time = datetime.now()
